﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StartsEAS_API.DAL.Core
{
    public class DBHelper
    {
        public static string ConnectionString { get; set; } = "server=sh-cynosdbmysql-grp-dyp7qfwe.sql.tencentcdb.com;port=20423; userid=root; password=Czy1001011;database=StarsEAS;";

        public static DataTable ExecuteTable(string sql, params MySqlParameter[] sqlParameters)
        {
            using MySqlConnection conn = new MySqlConnection(ConnectionString);
            conn.Open();
            MySqlCommand cmd = new MySqlCommand(sql, conn);
            cmd.Parameters.AddRange(sqlParameters);
            MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adapter.Fill(ds);
            return ds.Tables[0];
        }

        public static int ExecuteNonQuery(string sql, params MySqlParameter[] sqlParameters)
        {
            using MySqlConnection conn = new MySqlConnection(ConnectionString);
            conn.Open();
            MySqlCommand cmd = new MySqlCommand(sql, conn);
            cmd.Parameters.AddRange(sqlParameters);
            return cmd.ExecuteNonQuery();
        }
    }
}
